<?php

namespace Sifast\ProjectBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;

class CongeAdmin extends Admin {
     public function getTemplate($name) {
        switch ($name) {
            case 'list':
                return 'SifastProjectBundle:Conge:list.html.twig';
                break;
            default:
                return parent::getTemplate($name);
                break;
        }
    }

    protected function configureFormFields(FormMapper $formMapper) {
        $formMapper
                ->with('type')
                ->add('type', 'entity', array(
                    'class' => 'SifastProjectBundle:Type',
                ))
                ->end()
                ->with('dateDebut')
                ->add('jourDebut', 'date', array(
                    'label' => 'Jour de debut',
                    'widget' => 'single_text',
                    'format' => 'MM/dd/yyyy',
                    'attr' => array('class' => 'datepicker')
                ))
                ->add('timeJourDebut', 'choice', array(
                    'label' => '',
                    'choices' => array(
                        'Matinée' => 'Matinée',
                        'Après midi' => 'Après midi',
                        'Journée' => 'Journée',
                    )
                ))
                ->end()
                ->with('dateFin')
                ->add('jourFin', 'date', array(
                    'label'=> 'Jour de fin inclus',
                    'widget' => 'single_text',
                    'format' => 'MM/dd/yyyy',
                    'attr' => array('class' => 'datepicker')
                ))
                ->add('timeJourFin', 'choice', array(
                    'label' => '',
                    'choices' => array(
                        'Matinée' => 'Matinée',
                        'Après midi' => 'Après midi',
                        'Journée' => 'Journée',
                    )
                ))
                ->end()
                ->with('motif')
                ->add('motif')
                ->end()
                ->with('attachement')
                ->add('attachement', 'file')
                ->end();
        if ($this->isGranted('ROLE_ADMIN')) {
            $formMapper
                    ->add('resultat', 'choice', array(
                        'label'=>'Resposable:',
                        'expanded' => true,
                        'choices' => array('En attente' => 'En attente', 'Valider' => 'Valider', 'Refuser' => 'Refuser'),
                        'data' => '1',
                        'read_only' => true,
                        
                    ))
            ;
        } elseif ($this->isGranted('ROLE_USER')) {
            $formMapper
                    ->add('resultat', 'choice', array(
                        'label'=>'Resposable:',
                        'expanded' => true,
                        'choices' => array('En attente' => 'En attente', 'Valider' => 'Valider', 'Refuser' => 'Refuser'),
                        'data' => '1',
                    ))
            ;
        }
    }

    protected function configureDatagridFilters(DatagridMapper $datagridMapper) {
        $datagridMapper
                ->add('type')
                ->add('jourDebut')
                ->add('jourFin')
                ->add('motif');
    }

    protected function configureListFields(ListMapper $listMapper) {
        $listMapper
                ->addIdentifier('type')
                ->add('jourDebut')
                ->add('jourFin')
                ->add('motif')
                ->add('attachement');
    }

}